/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.util;

import java.lang.annotation.Annotation;

public class AnnotationMarker extends BaseMarker {
	private final Class<?> annotationClass;

	public AnnotationMarker(Class<?> annotationClass) {
		super(annotationClass.getName().toLowerCase());
		
		this.annotationClass = annotationClass;
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// TestFilter methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public boolean matches(Class<?> testClass) {
		Annotation[] annotations = testClass.getAnnotations();
		
		if (annotations == null) {
			return false;
		}

		for (Annotation annotation : annotations) {
			if (annotation.annotationType().equals(annotationClass)) {
				return true;
			}
		}

		return false;
	}
}
